package com.tjvib.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tjvib.R;
import com.tjvib.bean.MessageBean;

import java.util.List;

public class MessageAdapter extends BaseQuickAdapter<MessageBean, BaseViewHolder> {

    private Context context;
    private String icon_url, client_url;

    public MessageAdapter(int layoutResId, @Nullable List<MessageBean> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    public void setIcon_url(String icon_url) {
        this.icon_url = icon_url;
    }

    public void setClient_url(String client_url) {
        this.client_url = client_url;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, MessageBean messageGson) {
        baseViewHolder.setText(R.id.it_tv_y, messageGson.getMsg())
                .setText(R.id.it_tv_m, messageGson.getMsg());

        if (messageGson.getMsgType()) {
            baseViewHolder.findView(R.id.it_mes_y_layout).setVisibility(View.GONE);
            baseViewHolder.findView(R.id.it_mes_m_layout).setVisibility(View.VISIBLE);
        } else {
            baseViewHolder.findView(R.id.it_mes_y_layout).setVisibility(View.VISIBLE);
            baseViewHolder.findView(R.id.it_mes_m_layout).setVisibility(View.GONE);
        }

        if (icon_url != null && !icon_url.equals("")) {
            ImageView it_iv_icon = baseViewHolder.findView(R.id.it_iv_icon);
            Glide.with(context)
                    .load(icon_url)
                    .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                    .into(it_iv_icon);
        }

        if (client_url != null && !client_url.equals("")) {
            ImageView it_iv_client = baseViewHolder.findView(R.id.it_iv_client);
            Glide.with(context)
                    .load(client_url)
                    .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                    .into(it_iv_client);
        }
    }
}
